import requests
from bs4 import BeautifulSoup


def get_classroom(request):
    try:
        aid = str(request.POST.get("aid", 0))
        buildingid = str(request.POST.get("buildingid", 0))
        whichweek = str(request.POST.get("whichweek", 0))
        week = str(request.POST.get("week", 0))
        my_cookie = str(request.POST.get("my_cookie", 0))
        myurl = "https://jwk.lzu.edu.cn/academic/teacher/teachresource/roomschedule_week.jsdo"
        hd = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
            "Host": "jwk.lzu.edu.cn",
            "content-type": "application/x-www-form-urlencoded",
            "Referer": "https://jwk.lzu.edu.cn/academic/teacher/teachresource/roomschedulequery.jsdo",
            "Cookie": "JSESSIONID=" + my_cookie,
        }
        dt = {
            "aid": aid,
            "buildingid": buildingid,
            "whichweek": whichweek,
            "week": week,
        }
        r = requests.post(myurl, headers=hd, data=dt)
        print(r.text)
        res = {"code": 2, "html": r.text}
    except Exception as e:
        print(e)
        res = {"code": -1}
    result = HttpResponse(json.dumps(res))
    result["Access-Control-Allow-origin"] = "*"
    return result
